#include <stdio.h>
#include "cJSON.h"
#include "log/log.h"
struct log_handle *log_handle = NULL;
int log_with_file = 0;
int log_with_func = 0;
int log_with_line = 1;
int log_with_ts = 0;
int log_file_info_width = 40;
int log_func_info_width = 40;
int verbose =1;

void dododo(cJSON *current_item)
{
    if (current_item == NULL) return;
    if (current_item->type == cJSON_Array) {
        cJSON *c = current_item->child;
        for (; c; c = c->next) {
            dododo(c->child);
        }
    } else if (current_item->type == cJSON_Object) { current_item = current_item->child;  LOGERR("bug, fix me\n");
    } else {
        LLOG("%s\n", current_item->string);
        dododo(current_item->next);
    }
}

int main(int argc, char **argv)
{
    {
        char buf[] = "[{\"a\":1,\"b\":1},{\"c\":1, \"d\":1}]";
        cJSON *json_root = cJSON_ParseWithLength(buf, strlen(buf));
        printf("%s %p\n", buf, json_root);
        if (json_root)
        {
            dododo(json_root);
            cJSON_Delete(json_root);
        }
    }
#if 0
    FILE *fp = fopen("/dev/urandom", "r");
    if (fp) {
        int i;
        for (i = 0; i< 100; i++) {
#define SIZE 40960
            char buf[SIZE];
            fread(buf, 1, SIZE, fp);
            int j; for (j = 0 ; j < SIZE; j++) {
                buf[j] &= 0x7f;
                if (buf[j] == 0)
                    buf[j] = 1;
            }
            printf("%.*s\n", SIZE, buf);
            cJSON *json = cJSON_ParseWithLength(buf, SIZE);
            printf("%d json %p\n", i+1, json);
        }
        fclose(fp);
    }
#endif
    return 0;
}
